# -*- coding:utf-8 -*-

import os
import shutil
from mako.template import Template

"""
"""
ip_name = 'wangjun'
ip_name_upper = ip_name.upper()

"""
创建目录和相关文件
"""
if os.path.exists(ip_name):
    shutil.rmtree(ip_name)

os.mkdir(ip_name)
os.mkdir(ip_name + '/inc')
os.mkdir(ip_name + '/HAL')
os.mkdir(ip_name + '/HAL/inc')
os.mkdir(ip_name + '/HAL/src')

#os.system('type null > ' + ip_name + '/' + ip_name + '.v')
#os.system('type null > ' + ip_name + '/' + ip_name + '_register.v')
#os.system('type null > ' + ip_name + '/' + ip_name + '_logic.v')
#os.system('type null > ' + ip_name + '/' + ip_name + '_sw.tcl')

f1 = open(ip_name + '/' + ip_name + '.v', 'w')
f2 = open(ip_name + '/' + ip_name + '_register.v', 'w')
f3 = open(ip_name + '/' + ip_name + '_logic.v', 'w')
f4 = open(ip_name + '/' + ip_name + '_sw.tcl', 'w')

f5 = open(ip_name + '/inc/' + ip_name + '_regs.h', 'w')
f6 = open(ip_name + '/HAL/inc/' + ip_name + '.h', 'w')
f7 = open(ip_name + '/HAL/src/' + ip_name + '.c', 'w')

"""
"""
t = Template(filename='./template_file/template_ip_top.v') 
text = t.render(ip_name = ip_name, PARA1 = 'WIDTH')
f1.write(text)
f1.close()

t = Template(filename='./template_file/template_ip_register.v') 
text = t.render(ip_name = ip_name, PARA1 = 'WIDTH')
f2.write(text)
f2.close()

t = Template(filename='./template_file/template_ip_logic.v') 
text = t.render(ip_name = ip_name, PARA1 = 'WIDTH')
f3.write(text)
f3.close()

t = Template(filename='./template_file/template_ip_sw.tcl') 
text = t.render(ip_name = ip_name)
f4.write(text)
f4.close()

t = Template(filename='./template_file/template_ip_regs.h') 
text = t.render(ip_name = ip_name, ip_name_upper = ip_name_upper)
f5.write(text)
f5.close()

t = Template(filename='./template_file/template_ip.h') 
text = t.render(ip_name = ip_name, ip_name_upper = ip_name_upper)
f6.write(text)
f6.close()

t = Template(filename='./template_file/template_ip.c') 
text = t.render(ip_name = ip_name, ip_name_upper = ip_name_upper)
f7.write(text)
f7.close()
